home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / ccdl150l.zip / IO / SETVBUF.C < prev    next >
C/C++ Source or Header  |  1996-07-26  |  677b  |  38 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int setvbuf(FILE *stream, char *buf, int mode, size_t size)
  4. {
  5.     if (stream->token != FILTOK)
  6.         return 1;
  7.     switch (mode) {
  8.         case _IOFBF:
  9.         case _IOLBF:
  10.         case _IONBF:
  11.             break;
  12.         default:
  13.             return 1;
  14.     }
  15.     if (fflush(stream))
  16.         return 1;
  17.     if (stream->flags & _F_BUF)
  18.         free(stream->buffer);
  19.     stream->flags &= ~(_F_BUF | _F_LBUF);
  20.     stream->buffer = buf;
  21.     stream->bsize = size;
  22.     stream->level = 0;
  23.     switch (mode) {
  24.         case _IOFBF:
  25.             break;
  26.         case _IOLBF:
  27.             stream->flags |= _F_LBUF;
  28.             break;
  29.         case _IONBF:
  30.             stream->buffer = 0;
  31.             stream->bsize = 0;
  32.             break;
  33.         default:
  34.             return 1;
  35.     }
  36.     return 0;
  37.     
  38. }